<!--
 * @Description:input仿照淘宝搜索
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-14 09:33:04
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>input仿照淘宝搜索</title>

	<script>
		window.onload = function () {
			function $(id) {
				return document.getElementById(id)
			}
			$("txt").oninput=function(){
				if(this.value==""){
					$("message").style.display="block"
				}else{
					$("message").style.display="none"
				}
			}
		// $("message").onmouseover=function(){
		// 		this.select() //鼠标经过选择表单
    //   console.log("pppp")
		// 	}
		}
	</script>
</head>

<body>
	<style>
		.search {
			width: 300px;
			height: 30px;
			margin: 100px auto;
			position: relative;
		}

		.search input {
			width: 200px;
			height: 25px;

		}

		.search label {
			font-size: 12px;
			color: #ccc;
			position: absolute;
			top: 7px;
			left: 20px;
			cursor: text;
		}
	</style>
	<div>
		onfocus 获取焦点 <br>
		onblur 失去焦点 <br>
		oninput 用户输入事件 <br>
		<div class="search">
			<input type="text" id="txt" >
			<label for="txt" id="message">必败的国际大牌</label>
		</div>
	</div>
</body>

</html>